package com.wmx.entity;

import java.util.concurrent.Callable;
import java.util.concurrent.locks.Lock;

/**
 * @author:wmx 2025-03-12 11:22
 * 1、功能:
 * 2、参数{
 * <p>
 * <p>
 * }
 **/
public class Couple implements Callable<String> {
    private  static double trading  = 5000.00;
    private String lock = "lock";
    private  double money;
    private String amount;
    private  String sex;


    public Couple(double money, String amount, String sex) {

        this.money = money;
        this.amount = amount;
        this.sex = sex;
    }

    @Override
    public String call() {
        while (true){
            synchronized (lock) {
                try {
                    Thread.currentThread().sleep(100);
                    if ((this.trading - this.money) < 0) {
                        System.out.println("余额不足");
                        break;
                    } else {
                        this.trading -= this.money;
                        System.out.println(toString());
                        break;
                    }

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.sex+"用"+this.amount+"取钱:"+this.money+",剩余:"+this.trading;
    }


}
